Skip to content

fix(api): preserve text in compact provider SSE data fields - #1397

Closed
darkbloombugs wants to merge 1 commit into
Layr-Labs:masterfrom
darkbloombugs:bugfix/provider-sse-framing-20261008
Closed

darkbloombugs wants to merge 1 commit into
Layr-Labs:masterfrom
darkbloombugs:bugfix/provider-sse-framing-20261008

Conversation

@darkbloombugs

@darkbloombugs darkbloombugs commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Provider SSE JSON fields permit data:{...} as well as data: {...}. Two coordinator response decoders require the space, silently skip the compact form and return successful responses with empty text.

Strip data: before the existing whitespace trim in ExtractMessageWithReasoningPolicy and parseStreamChunkChoices. This preserves text for all four non-streaming endpoints and translated Completions, Messages and Responses streams. Ordinary chat streaming already forwards the text and is a passing control. The production change is two lines; decoding and lifecycle ownership stay unchanged.

Contract and related work

ProviderLoop+SSEParser.swift explicitly implements W3C EventStream framing, including the optional post-colon space; the protocol describes the payload as SSE text. The HTML standard's field parsing rule makes that space optional. This is a supported serialization defect reproduced through the HTTP API. The pinned stock MLX encoder emits the spaced form, so no current stock-provider incident is claimed.

Fresh issue/PR deduplication found no usable duplicate. The relocated decoders at the inspected head of open #1056 still require the space; #1365, #1350, #1349 and #1396 cover other behavior. No issue closure is requested.

Before

flowchart TD
  P["Provider sends data:JSON without a space"] --> W["Encrypted WebSocket and inference relay"]
  W --> D["ExtractMessageWithReasoningPolicy or parseStreamChunkChoices"]
  D --> X["Space-dependent prefix remains; JSON decode fails"]
  X --> H["HTTP success with empty text"]
  classDef data fill:#fef3c7,stroke:#b45309,color:#78350f
  classDef code fill:#dbeafe,stroke:#2563eb,color:#1e3a8a
  classDef failure fill:#fee2e2,stroke:#dc2626,color:#7f1d1d
  class P data
  class W,D code
  class X,H failure
Loading

After

flowchart TD
  P["Provider sends either data-field spacing"] --> W["Same encrypted WebSocket and relay"]
  W --> D["Both response decoders strip data: then trim"]
  D --> J["Existing JSON decoder and text assembly"]
  J --> H["HTTP response preserves Hello world"]
  classDef data fill:#fef3c7,stroke:#b45309,color:#78350f
  classDef code fill:#dbeafe,stroke:#2563eb,color:#1e3a8a
  classDef success fill:#dcfce7,stroke:#16a34a,color:#14532d
  class P data
  class W,D,J code
  class H success
Loading

Amber is provider data, blue is existing code flow, red is the lost text, and green is the corrected result.

Validation

Base: e3575b993cb56f1930b9ee7825c0d0553410e820; Go 1.26.8, darwin/arm64, CGO_ENABLED=0. Unchanged modules, offline Go checks, CPU-only, at most two execution threads and 600-second command caps.

  • Baseline: go test -p=1 -mod=readonly -count=1 -timeout=500s ./coordinator/tests/api/inference/contracts -run '^TestProviderSSEOptionalSpaceHTTP$' — 7 failures, 9 passing controls. Every failure is HTTP 200 with empty text instead of Hello world.
  • Identical regression with the two-line fix — 16/16 pass. Four endpoints × streaming/non-streaming × spaced/compact data fields. Assertions include exact text, successful status, stream content type, terminal count and Chat/Completions finish count.
  • Dedicated refactor pass: no changes warranted. Separate correctness review verified exact patch/source hashes, the real caller path and retained baseline/fixed evidence; no blocking findings. Reviewers did not independently run tests.
  • Full coordinator suite: go test -p=1 -mod=readonly -count=1 -timeout=500s ./coordinator/... — 10,286 test/subtest passes, 235 skips, completed in 483 seconds. The repository results verifier confirms all 378 package completions with no missing or duplicate results; all 16 new cases pass in this run too.
  • Coordinator build, targeted go vet, module verification and 20 runner guard tests pass.
  • make docs-impact-check BASE=e3575b993cb56f1930b9ee7825c0d0553410e820 and make docs-check pass (363 documentation files).

Skipped checks require disposable PostgreSQL, opt-in media/qualification fixtures, real sidecar binaries, performance opt-in or additional CPU concurrency. They are not counted as passes.

The canonical API contract, consumer quickstart and topical Unreleased changelog are updated. No new fields, configuration, dependency, protocol or release version.

Limits

The regression exercises the real HTTP router, in-memory store, encrypted scripted provider WebSocket, relay, response decoders and HTTP output. The provider uses fixture credentials and synthetic chunks/usage; no model, real account, production database or external inference is used. Existing provider completion supplies authoritative usage. This patch proves text preservation, not full SSE conformance: multiline/named events, BOM handling, metadata normalization and neighboring usage parsers are outside its scope. No live provider, GPU, race-detector, deployment, release or historical-incident qualification is claimed.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

@vercel

vercel Bot commented Oct 8, 2026

Copy link
Copy Markdown

@darkbloombugs is attempting to deploy a commit to the EigenLabs Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant